/*
 * Copyright (c) 2010, Nikolaus Moll
 * All rights reserved.
 */
package net.miblounge.gradecalculator.core.descriptors.modulelistitems;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

import net.miblounge.gradecalculator.core.descriptors.courses.Course;
import net.miblounge.gradecalculator.core.descriptors.courses.CourseDescription;

@XmlRootElement(namespace = "http://gradecalculator.net/")
public class IndividualModule extends Module implements Cloneable {
	private float moduleECTS;
	private int moduleHoursPerWeek;
	
	public IndividualModule()
	{
		this("");
	}
	
	public IndividualModule(final String name)
	{
		this(name, -1);
	}
	
	public IndividualModule(final String name, final int ects) {
		super(name);
		moduleECTS = ects;
	}

	@Override
	@XmlElement(name = "ects") 
	public float getECTS() {
		return moduleECTS;
	}
	public void setECTS(final float ects) {
		this.moduleECTS = ects;
	}
	
	@Override
	@XmlElement(name = "hoursperweek") 
	public int getHoursPerWeek() {
		return moduleHoursPerWeek;
	}
	public void setHoursPerWeek(final int moduleHoursPerWeek) {
		this.moduleHoursPerWeek = moduleHoursPerWeek;
	}

	@Override
	@XmlTransient 
	public ModuleType getModuleType() {
		return ModuleType.IndividualModule;
	}

	@Override
	public void addCourse(final Course course)
	{
		if (!(course instanceof CourseDescription)) {
			throw new IllegalStateException("Only CourseDescriptions can be added to an IndividualModule");
		}
		
		final CourseDescription courseDescription = (CourseDescription)course;
		courseDescription.setParentModule(this);

		super.addCourse(course);
	}
	
	
	
	@Override
	public IndividualModule clone()
	{
		final IndividualModule result = (IndividualModule)super.clone();
		result.moduleECTS = moduleECTS;	// think about deep copy
		return result;
	}
}
